<template>
	<view class="container">
		<view>
			<uni-popup ref="popup" type="top" background-color="#fff">
				<view class="popup-content">
					<uni-forms ref="queryForm" :modelValue="queryParams">
						<uni-forms-item label="案件编号" label-width="85">
							<uni-easyinput v-model="queryParams.caseCode" placeholder="案件编号"></uni-easyinput>
						</uni-forms-item>
						<uni-forms-item label="上报时间" label-width="85">
							<uni-datetime-picker v-model="queryParams.reportTime" type="daterange"/>
						</uni-forms-item>
					</uni-forms>
					<view style="display: flex;">
						<button size="mini" class="common-btn other-btn" @click="handleRepeat">重置</button>
						<button size="mini" class="common-btn primary-btn" @click="handleQuery">查询</button>
					</view>
				</view>
			</uni-popup>
		</view>
		<view class="uni-padding-wrap">
			<uni-segmented-control :current="current" :values="items" :style-type="styleType"
				:active-color="activeColor" @clickItem="onClickItem" />
		</view>
		<view class="uni-list">
			<case-list-content :list-data="listData" :rows="rows">
				<template #cssx="item" v-if="current == '0'">
					<view class="list-row" >
						<view class="list-row-label" style="color: #ff0000;">超时时限</view>
						<view class="list-row-content" style="color: #ff0000;">{{item.data.cssx}}</view>
					</view>
				</template>
				<template #isReply="item" v-if="current == '1'">
					<view class="list-row" >
						<view class="list-row-label" >督办答复</view>
						<view class="list-row-content" style="color: #ff0000;">{{item.data.isReply}}</view>
					</view>
				</template>
				<template #btns="item" >
					<button class="common-btn primary-btn" v-if="current == '0'"  size="mini" @click="handleDeal(item.data,'deal')">巡查录入</button>
					<button class="common-btn other-btn" v-else  size="mini" @click="handleDeal(item.data,'view')">查看详情</button>
				</template>
			</case-list-content>
		</view>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>

<script>
	import { getDicts } from "@/api/system/dict/data";
	import { dateUtils } from  '@/utils/util.js';
	import {
	  listPubPatrolTask
	} from "@/api/pub/pubPatrolTask";
	export default {
		data(){
			return {
				items: ['待办巡查', '已办巡查'],
				current: 0,
				activeColor: '#2359C1',
				styleType: 'button',
				queryParams:{
					caseCode:"",
					reportTime:[]
				},
				page:1,
				size:10,
				total:0,
				listData: [],
				//列表显示字段
				rows:[{
					labelName:"计划名称",
					valueName:"planName"
				},{
					labelName:"巡查范围",
					valueName:"patrolObjNames"
				},{
					labelName:"开始时间",
					valueName:"patrolStartTime"
				},{
					labelName:"结束时间",
					valueName:"patrolEndTime"
				}],
				reload: false,
				status: 'noMore',
				adpid: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				sourceOptions:[]
			}
		},
		methods:{
			onClickItem(e){
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
					this.getListData();
				}
			},
			getListData(){
				this.page = 1;
				this.reload = true;
				this.listData = [];
				console.log(JSON.stringify(this.queryParams));
				if(this.current == 0){
					//待办
					this.getList();
				}else{
					//已办
					this.getDoneList();
				}
			},
			getList() {
				uni.showLoading({
					title:"加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if(this.reload){
					uni.stopPullDownRefresh();
				}
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				this.queryParams.patrolObjType = "1";
				this.queryParams.patrolStatus  = "1";
				//this.queryParams.isSupervise = "0";
				listPubPatrolTask(this.queryParams).then(res => {
					// console.log(JSON.stringify(res));
					uni.hideLoading();
					if(res.code == 200){
						let list = res.rows;
						this.total = res.total;					
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;
					}
				})
			},
			getDoneList(){
				uni.showLoading({
					title:"加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if(this.reload){
					uni.stopPullDownRefresh();
				}
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				this.queryParams.patrolObjType = "1";
				this.queryParams.patrolStatus  = "2";
				listPubPatrolTask(this.queryParams).then(res => {
					console.log(JSON.stringify(res));
					uni.hideLoading();
					if(res.code == 200){
						let list = res.rows;
						this.total = res.total;					
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;
					}
				})
			},
			handleQuery(){
				if(this.queryParams.reportTime &&　this.queryParams.reportTime.length>0){
					let params = {
						"rptTimeStart":this.queryParams.reportTime[0]+" 00:00:00",
						"rptTimeEnd":this.queryParams.reportTime[1]+" 23:59:59"
					}
					this.queryParams.params = params;
				}
				this.getListData();
				this.$refs.popup.close()
			},
			handleRepeat(){
				this.queryParams = {};
			},
			handleDeal(item,type){
				console.log(JSON.stringify(item));
				// console.log(item.caseId);
				if(type == "deal"){
					uni.navigateTo({
						url:'xcinfo/xcinfo?oper=deal&rowData='+JSON.stringify(item)
					})
				}else{
					uni.navigateTo({
						url:'xcinfo/xcinfo?oper=view&rowData='+JSON.stringify(item)
					})
				}
				
			}
		},
		
		onLoad() {
			//问题来源
			getDicts("case_source").then(response => {
				this.sourceOptions = response.data;
			});
			
			this.page = 1;
			this.reload = true;
			this.listData = [];
			this.getList();
		},
		onNavigationBarButtonTap : function (e) {
			this.$refs.popup.open()
		},
		onPullDownRefresh(){
			this.getListData();
		},
		onReachBottom(){
			this.page++;
			if(this.listData.length < this.total){
				this.status = 'more';
			}else{
				this.status = 'noMore';
				return;
			}
			if(this.current == 0){
				//待办
				this.getList();
			}else{
				//已办
				this.getDoneList();
			}
		}
	}
</script>

<style lang="scss">
	.uni-padding-wrap {
		padding: 0px 10px;
	}
	.popup-content {
		padding: 15px;
		height: 500px;
		background-color: #fff;
	}
	.list-row{
		display: flex;
		padding-bottom: 10px;
	}
	.list-row-label{
		font-family: MicrosoftYaHei;
		font-size: 14px;
		font-weight: normal;
		line-height: 17px;
		letter-spacing: 0px;
		color: #9DA0AA;
		width: 25%;
	}
	.list-row-content{
		font-family: MicrosoftYaHei;
		font-size: 14px;
		font-weight: normal;
		line-height: 17px;
		letter-spacing: 0px;
		width: 75%;
		color: #353B50;
		white-space:nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}
	.nav-btn{
		margin-right: 15px;
	}
</style>